home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / Math.h < prev    next >
C/C++ Source or Header  |  1992-04-27  |  5KB  |  234 lines

  1. #ifndef Math_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define Math_First
  7.  
  8. #include "Types.h"
  9.  
  10. class Math {
  11. public:
  12.     static const double
  13.        Pi,
  14.        E;
  15.  
  16.     // Trigo
  17.     static double Sin(double);
  18.     static double Cos(double);
  19.     static double ASin(double);
  20.     static double ACos(double);
  21.     static double ATan(double);
  22.     static double ATan2(double, double);
  23.     static int Hypot(int x, int y);     // sqrt(px*px + py*py)
  24.     static double Hypot(double x, double y);
  25.  
  26.     static void Sincos(double a, double *sin, double *cos);
  27.     static double Atan2(int x, int y);
  28.     static double Atan2(double fx, double fy);
  29.     
  30.     // Misc
  31.     static int NextPrime(int x);        // least prime number greater than x
  32.     static int Sqrt(int x);
  33.     static double Sqrt(double x);
  34.     static double Ceil(double x);
  35.     static double Floor(double x);
  36.     static double Exp(double);
  37.     static double Power(double x, double y);
  38.  
  39.     // Abs
  40.     static short Abs(short d);
  41.     static int Abs(int d);
  42.     static long Abs(long d);
  43.     static double Abs(double d);
  44.  
  45.     // Even/Odd
  46.     static int Even(long a);
  47.     static int Odd(long a);
  48.  
  49.     // Signum
  50.     static short Sign(short a);
  51.     static int Sign(int a);
  52.     static long Sign(long a);
  53.     static double Sign(double a);
  54.  
  55.     // Min
  56.     static short Min(short a, short b);
  57.     static u_short Min(u_short a, u_short b);
  58.     static int Min(int a, int b);
  59.     static u_int Min(u_int a, u_int b);
  60.     static long Min(long a, long b);
  61.     static u_long Min(u_long a, u_long b);
  62.     static double Min(double a, double b);
  63.  
  64.     // Max
  65.     static short Max(short a, short b);
  66.     static u_short Max(u_short a, u_short b);
  67.     static int Max(int a, int b);
  68.     static u_int Max(u_int a, u_int b);
  69.     static long Max(long a, long b);
  70.     static u_long Max(u_long a, u_long b);
  71.     static double Max(double a, double b);
  72.  
  73.     // Range
  74.     static short Range(short lb, short ub, short x);
  75.     static int Range(int lb, int ub, int x);
  76.     static long Range(long lb, long ub, long x);
  77.     static double Range(double lb, double ub, double x);
  78. };
  79.  
  80. //---- Sign --------------------------------------------------------------------
  81.  
  82. inline short Math::Sign(short a)
  83. {
  84.     return (a == 0) ? 0 : ( (a > 0) ? 1 : -1 );
  85. }
  86.  
  87. inline int Math::Sign(int a)
  88. {
  89.     return (a == 0) ? 0 : ( (a > 0) ? 1 : -1 );
  90. }
  91.  
  92. inline long Math::Sign(long a)
  93. {
  94.     return (a == 0) ? 0 : ( (a > 0) ? 1 : -1 );
  95. }
  96.  
  97. inline double Math::Sign(double a)
  98. {
  99.     return (a == 0.0) ? 0 : ( (a > 0.0) ? 1 : -1 );
  100. }
  101.  
  102. //---- even/odd ----------------------------------------------------------------
  103.  
  104. inline int Math::Even(long a)
  105. {
  106.     return ! (a & 1);
  107. }
  108.  
  109. inline int Math::Odd(long a)
  110. {
  111.     return (a & 1);
  112. }
  113.  
  114. //---- Abs ---------------------------------------------------------------------
  115.  
  116. inline short Math::Abs(short d)
  117. {
  118.     return (d > 0) ? d : -d;
  119. }
  120.  
  121. inline int Math::Abs(int d)
  122. {
  123.     return (d > 0) ? d : -d;
  124. }
  125.  
  126. inline long Math::Abs(long d)
  127. {
  128.     return (d > 0) ? d : -d;
  129. }
  130.  
  131. inline double Math::Abs(double d)
  132. {
  133.     return (d > 0) ? d : -d;
  134. }
  135.  
  136. //---- Min ---------------------------------------------------------------------
  137.  
  138. inline short Math::Min(short a, short b)
  139. {
  140.     return a <= b ? a : b;
  141. }
  142.  
  143. inline u_short Math::Min(u_short a, u_short b)
  144. {
  145.     return a <= b ? a : b;
  146. }
  147.  
  148. inline int Math::Min(int a, int b)
  149. {
  150.     return a <= b ? a : b;
  151. }
  152.  
  153. inline u_int Math::Min(u_int a, u_int b)
  154. {
  155.     return a <= b ? a : b;
  156. }
  157.  
  158. inline long Math::Min(long a, long b)
  159. {
  160.     return a <= b ? a : b;
  161. }
  162.  
  163. inline u_long Math::Min(u_long a, u_long b)
  164. {
  165.     return a <= b ? a : b;
  166. }
  167.  
  168. inline double Math::Min(double a, double b)
  169. {
  170.     return a <= b ? a : b;
  171. }
  172.  
  173. //---- Max ---------------------------------------------------------------------
  174.  
  175. inline short Math::Max(short a, short b)
  176. {
  177.     return a >= b ? a : b;
  178. }
  179.  
  180. inline u_short Math::Max(u_short a, u_short b)
  181. {
  182.     return a >= b ? a : b;
  183. }
  184.  
  185. inline int Math::Max(int a, int b)
  186. {
  187.     return a >= b ? a : b;
  188. }
  189.  
  190. inline u_int Math::Max(u_int a, u_int b)
  191. {
  192.     return a >= b ? a : b;
  193. }
  194.  
  195. inline long Math::Max(long a, long b)
  196. {
  197.     return a >= b ? a : b;
  198. }
  199.  
  200. inline u_long Math::Max(u_long a, u_long b)
  201. {
  202.     return a >= b ? a : b;
  203. }
  204.  
  205. inline double Math::Max(double a, double b)
  206. {
  207.     return a >= b ? a : b;
  208. }
  209.  
  210. //---- Range -------------------------------------------------------------------
  211.  
  212. inline short Math::Range(short lb, short ub, short x)
  213. {
  214.     return x < lb ? lb : (x > ub ? ub : x);
  215. }
  216.  
  217. inline int Math::Range(int lb, int ub, int x)
  218. {
  219.     return x < lb ? lb : (x > ub ? ub : x);
  220. }
  221.  
  222. inline long Math::Range(long lb, long ub, long x)
  223. {
  224.     return x < lb ? lb : (x > ub ? ub : x);
  225. }
  226.  
  227. inline double Math::Range(double lb, double ub, double x)
  228. {
  229.     return x < lb ? lb : (x > ub ? ub : x);
  230. }
  231.  
  232. #endif
  233.  
  234.